﻿using UnityEngine;
using FairyGUI;

/// <summary>
/// 重连窗口
/// </summary>
public class UIGameReconnectWindow : UIPopupWindow
{
	static UIGameReconnectWindow _inst;
	public UIGameReconnectWindow ()
	{
		_inst = this;

		// 加载界面
		base.Init (UIPackage.CreateObject ("游戏界面", "网络中断").asCom);

		// 初始化重连按钮
		GButton reccBtn = uiComp.GetChild ("重连按钮").asButton;
		reccBtn.onClick.Add (() => {
			_Close();
			GameController.inst.EnqueueMessage(
				new BaseProceduar.Message(Commands.CMD_MOD_MSG, GameCommands.CMD_RECONNECT)
			);
		});

		// 初始化退出游戏按钮
		GButton exitBtn = uiComp.GetChild ("退出游戏按钮").asButton;
		exitBtn.onClick.Add (() => {
			Application.Quit();
		});
	}

	void _Close() {
		DebugInfo.Log ("关闭 重连窗口");

		AudioController.inst.PlayUIClickEffect ();
		uiComp.RemoveFromParent ();
		uiComp.Dispose ();
		base.Close ();

		_inst = null;
	}

	public static void CloseWindow() {
		if (_inst != null) {
			_inst._Close ();
		}
	}

	/// <summary>
	/// 弹出窗口
	/// </summary>
	public static void Popup ()
	{
		DebugInfo.Log ("打开 重连窗口");
		UIRootController.inst.PopupWindow (new UIGameReconnectWindow ());
	}
}
